<template>
  <h2>readonly 与 shallowReadonly</h2>
  <h3>state:{{ state }}</h3>
  <h3>state:{{ state3 }}</h3>
  <button @click="update">更新数据</button>
</template>

<script lang='ts'>
import { defineComponent, reactive, readonly, shallowReadonly } from "vue";

export default defineComponent({
  name: "App",
  setup() {
    const state = reactive({
      name: "极为",
      age: 20,
      car: {
        name: "奔驰",
        color: "yellow",
      },
    });
    const state2 = readonly(state);
    const state3 = shallowReadonly(state);
    const update = () => {
      // state2.name += '==';//error(readonly)
      // state2.car.name += '==';//error(readonly)

      //state3.name += '==';//error(shallowReadonly)
      state3.car.name += "=="; //修改成功
    };
    return {
      state2,
      state3,
      update,
    };
  },
});
</script>
